package com.jzr.medical.db1.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.medical.common.LayServiceImpl;
import com.jzr.medical.db1.mapper.TMenuMapper;
import com.jzr.medical.db1.mapper.TRoleMenuRefMapper;
import com.jzr.medical.db1.model.TMenu;
import com.jzr.medical.db1.model.TRoleMenuRef;
import com.jzr.medical.db1.service.MenuService;
import com.jzr.medical.db1.vo.MenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

@Service
public class MenuServiceImpl extends LayServiceImpl<TMenuMapper,TMenu,MenuVo,Integer> implements MenuService {
    @Autowired
    private TRoleMenuRefMapper roleMenuRefMapper;

    @Override
    public boolean removeById(Serializable id) {
        QueryWrapper<TRoleMenuRef> qrf = new QueryWrapper<>();
        qrf.eq(TRoleMenuRef.MenuId_,id);
        roleMenuRefMapper.delete(qrf);

        return super.removeById(id);
    }

    @Override
    public boolean isHasChild(Integer id) {
        QueryWrapper<TMenu> qw = new QueryWrapper<>();
        qw.eq(TMenu.ParentId_,id);
        long count = baseMapper.selectCount(qw);
        return count > 0;
    }

}
